<template>
	<view>
		<uni-nav-bar left-icon="arrowthinleft" :title="title" :border="false" :fixed="true" bg="bg-fff" color="#333"
			@clickLeft="goBack()"></uni-nav-bar>
		<view class="w100 bg-f7f7f7" style="height: 10rpx;"></view>
		<view class="padding-x-24 padding-y-10 flex align-center justify-between solid-bottom">
			<view class="fs-26 color-333">姓名<text class="color-zhuse">*</text></view>
			<input type="text" v-model="subInfo.name" class="fs-26 color-aaa flex1 text-right h40" placeholder="请输入姓名">
		</view>
		<view class="padding-x-24 padding-y-10 flex align-center justify-between solid-bottom">
			<view class="fs-26 color-333">账号<text class="color-zhuse">*</text></view>
			<input type="text" v-model="subInfo.account" class="fs-26 color-aaa flex1 text-right h40"
				placeholder="请输入账号">
		</view>
		<view class="padding-x-24 margin-top-30 fs-26 color-333">{{subInfo.method == 'wechat'?'微信':'支付宝'}}收款码<text class="color-zhuse">*</text> </view>
		<view class="padding-x-24 margin-top-40 flex align-center justify-center">
			<view @tap="uploadImg()" class="img_box w50 flex align-center justify-center">
				<image v-if="!code" src="../../static/img/upload.png" class="add_icon"></image>
				<image v-else :src="code" class="w100" style="height: 100%;"></image>
			</view>
		</view>


		<view class="padding-x-60 margin-y-48 padding-bottom-30">
			<view @tap="submit()" class="callBtn color-fff radius60 h40 fs-28 text-center">确定</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				subInfo: {
					method: "",
					account: "",
					name: "",
					code: "",
				},
				code: "",
				status: '',
				title:''
			}
		},
		onLoad(opt) {
			this.subInfo.method = opt.type;
			if(opt.type == 'wechat'){
				this.title = '绑定微信账号'
			}
			if(opt.type == 'alipay'){
				this.title = '绑定支付宝账号'
			}
			this.init()
		},
		methods: {
			init(){
				this.$api.my_cash_info({type:this.subInfo.method}).then(res => {
					if (res.code == 1) {
						if(res.data){
							this.subInfo.account = res.data.account;
							this.subInfo.name = res.data.name;
							this.subInfo.code = res.data.code;
							this.code = res.data.code_img;
						}
					}
				})
			},
			uploadImg(type) {
				this.$tool.upload().then(res => {
					this.code = res.showImg;
					this.subInfo.code = res.id;
				})
			},
			submit() {
				this.$api.cash_set(this.subInfo).then(res => {
					this.$msg(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 400)
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.img_box {
		border: 1rpx dashed #eee;
		height: 400rpx;

		.add_icon {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.callBtn {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 60rpx;
		background: linear-gradient(to bottom, #FDA730, #FE810A);
	}
</style>
